# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libassuan
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.4
pkgrel=1
pkgdesc="A IPC library used by some GnuPG related software (mingw-w64)"
arch=('any')
license=('GPL')
url="https://gnupg.org/related_software/libassuan"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.sig}
        0001-fix-def-files.mingw.patch
        0002-enable-silent-rules.mingw.patch
        0004-enable-gnu.mingw.patch
        0005-better-check-for-stpcpy.mingw.patch)
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA'
              'D8692123C4065DEA5E0F3AB5249B39D24F25E3B6'
              '46CC730865BB5C78EBABADCF04376F3EE0856959'
              '031EC2536E580D8EA286A9F22071B08A33BD3F06'
              'D238EA65D64C67ED4C3073F28A861B1C7EFD60D9')
sha256sums=('c080ee96b3bd519edd696cfcebdecf19a3952189178db9887be713ccbcb5fbf0'
            'SKIP'
            'b74089b88544da56bf4e6589516264b30757b9393fb8bdd916ff7c03cbba6e19'
            '14a46889fc0a9d3d8c0426983e9a467da46d95dfd77156fc343de8c598504d05'
            '4e2f030dbfd0d1069a1d1015ac725509f1a8ac136ff83453d7a9ce31103e8263'
            'f907e774b3a065b66e4bdfa67000e6bc30a9e49184b1260b64def03914eba56f')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-fix-def-files.mingw.patch
  patch -p1 -i ${srcdir}/0002-enable-silent-rules.mingw.patch
  patch -p1 -i ${srcdir}/0004-enable-gnu.mingw.patch
  patch -p1 -i ${srcdir}/0005-better-check-for-stpcpy.mingw.patch

  autoreconf -fi
}

build() {
  if [ ${MINGW_CHOST} = "x86_64-w64-mingw32" ]; then
    CFLAGS+=" -DHAVE_DOSISH_SYSTEM=1"
  fi
  [ -d ${srcdir}/build-${MINGW_CHOST} ] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  #make check
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
